<template>
  <van-popup v-model="popupShow" position="center" style="width: 100%;height: 100%">
        <div class="avatar_box">
            <div class="image" v-for="item of 20" :key="item">
                <img :src="require(`@/assets/image/avatar/${item}.png`)" @click="selectAvatar(item)" class="avatar" alt="">
                <div class="active" v-if="item == current">
                    <img src="@/assets/image/dui.png" class="icon" alt="">
                </div>
            </div>

        </div>
  </van-popup>
</template>

<script>
import { NavBar, Toast, Popup } from "vant";
import { apiRefreshAvatar } from "@/API/common";
export default {
    components: {
        [NavBar.name]: NavBar,
        [Popup.name]: Popup
    },
    data() {
        return {
            current: 1,
          popupShow: false,
        }
    },
    methods: {
      show(current) {
        this.current = current || 1
        this.popupShow = true
      },
      hide() {
        this.popupShow = false
      },
        selectAvatar(item) {
            this.current = item
            // this.$emit('selectAvatar', item)
          this.submitHandle()
        },
        async submitHandle() {
            Toast.loading({
                duration: 0,
                forbidClick: true,
                message: ""
            });
            await apiRefreshAvatar({ idx: this.current })
          await this.$store.dispatch('getUserInfo')
            Toast.clear();
            this.hide()
        }
    }
}
</script>

<style lang="scss" scoped>
.avatar_box {
    width: 100%;
    height: 100vh;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    padding: 30px 19px;
  box-sizing: border-box;
  overflow: auto;

    .image {
        position: relative;
        border-radius: 50%;
        margin-right: 25px;
        margin-bottom: 25px;

        &:nth-child(4n) {
            margin-right: 0;
        }

        .active {
            width: 20px;
            height: 20px;
            background: var(--main-color);
            position: absolute;
            bottom: 2px;
            right: 2px;
            display: flex;
            justify-content: center;
            align-items: center;
            border-radius: 50%;
            border: 1px solid #fff;

            .icon {
                width: 8px;
                height: 10px;
            }
        }
    }

    .avatar {
        width: 64px;
        height: 64px;
        border-radius: 50%;



    }
}
</style>
